import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton } from '../Common/options'
import { MaterialBatch } from '../Common/Conversion'

export const MaterialTrace = async ({ url, OptionsEvent, ClientData, Permission }) => {
    const materialBatchUuid = await MaterialBatch()
    let data = {
        pageSize: 10,
        params: { pageIndex: 1 },
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            Permission?.findIndex(v => v.uuid === 'a54b82ee-83f0-4a4c-8102-4fc0e56da37c') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} url={url} type="primary" icon="add" title="新增材料追溯" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.SearchSort, selectType: 'MaterialTrace' },
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization },
            { ...commonTableList.tableName, title: '追溯名称' },
            {
                dataIndex: 'traceTime',
                title: '使用日期',
                valueType: 'Date',
                showTime: true,
                rules: true,
                width: 180,
            },
            {
                dataIndex: 'materialTypeName',
                title: '材料类别',
                valueType: 'input',
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
                width: 180,
            },
            {
                dataIndex: 'materialBatchUuid',
                title: '材料批次',
                valueType: 'select',
                valueEnum: materialBatchUuid,
                rules: true,
                width: 180,
            },
            {
                dataIndex: 'materialName',
                title: '材料名称',
                valueType: 'input',
                hideInAdded: true,
                hideInModify: true,
                width: 180,
            },
            {
                dataIndex: 'spec',
                title: '材料规格',
                valueType: 'hidden',
                width: 180,
                hideInSearch: true,
            },
            {
                dataIndex: 'unit',
                title: '材料单位',
                valueType: 'hidden',
                width: 180,
                hideInSearch: true,
            },
            {
                dataIndex: 'num',
                valueType: 'inputNumber',
                title: '数量',
                rules: true,
                hideInSearch: true,
                width: 180,
            },
            commonTableList.BeginEntryTime,
            commonTableList.EndEntryTime,
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        Permission.findIndex(v => v.uuid === 'a2396229-69d1-4161-82a1-7e3072b9f54c') !== -1 && (
                            <ModDataButton
                                OptionsEvent={OptionsEvent}
                                key="modify"
                                title="修改"
                                url={url}
                                data={record}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === 'a3aa7879-1e48-41cc-ba3b-e7f613d08b9a') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
